package com.lianniu.web.baseService.user.service.impl;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.lianniu.web.base.BaseResult;
import com.lianniu.web.baseService.user.dao.IBuyerDao;
import com.lianniu.web.baseService.user.model.BuyerinfoVo;
import com.lianniu.web.baseService.user.service.IBuyerService;
import com.lianniu.web.buyerProduct.model.BuyerConsigneeVo;
import com.lianniu.web.buyerProduct.service.IBuyerInfoService;
import com.lianniu.web.constants.ErrorCode;
import com.lianniu.web.util.StringUtil;
@Service
public class BuyerServiceImpl implements IBuyerService{
    private final static Logger logger = Logger.getLogger(BuyerServiceImpl.class);
    
    @Resource
    private IBuyerDao buyerDao;
    @Resource
    private IBuyerInfoService buyserInfoService;
    
	@Override
	@Transactional
	public BaseResult insertBuyerinfoVo(BuyerinfoVo buyer) {
        logger.info("insertBuyerinfoVo begin");
        logger.info("insertBuyerinfoVo: input data check begin");
        logger.info("insertBuyerinfoVo dictType:" + JSON.toJSONString(buyer));
        BaseResult baseResult;
        if (StringUtil.isEmpty(buyer.getBuyerTel())) {

            baseResult = BaseResult.fail(ErrorCode.ParaCheckErrorRetCode,
                            ErrorCode.ParaCheckErrorRetInfo);
            return baseResult;
        }
        logger.info("insertBuyerinfoVo: input data check end");
        Integer i = buyerDao.addBuyer(buyer);
        return BaseResult.success(i);
	}

    @Override
    public boolean isExistMobile(String mobile) {
        logger.info("BuyerServiceImpl isExistMobile begin.");
        logger.info("input data check begin.");
        if (StringUtil.isEmpty(mobile)) {
            return false;
        }
        logger.info("input data check end.");

        logger.info("isExistMobile begin.");
        boolean isExistFlg = buyerDao.isExistMobile(mobile);
        boolean retFlg = isExistFlg ? false:false  ;
        logger.info("isExistMobile end.");

        logger.info("BuyerServiceImpl isExistMobile end.");
        return retFlg;
    }

	@Override
	public BaseResult selectBuyerById(String id) {
		  logger.info("selectByUsersId begin");
	        logger.info("selectByUsersId id:"+id);
	        return BaseResult.success(buyerDao.selectBuyerById(id));
	}

}
